$(function(){
	//全选\全部取消
	$('input[name=Checkall]').click(function(){
		if($(this).is(':checked')){
			$('input[name=sids]').each(function(){
				this.checked=true;
			});
		}else{
			$('input[name=sids]').attr('checked',false);
		}
	});


	//服务删除（多选）
	$('.ServiceDels').click(function(){
		if(!confirm('确认删除选中？')){
			exit;
		}
		var arr = new Array();
		var str = $('input:checked').each(function(){
			arr.push(this.value);
		});
		var sids = arr.join(',');
		$.ajax({
			url:'http://www.service.top/index.php/Admin/Index/set_tokens',
			type:'post',
			data:{
				TokenName:'ServiceDels',
			},
			success:function(ServiceDels){
				$.ajax({
					url:'http://www.service.top/index.php/Model/ListService/dels',
					type:'post',
					data:{
						sids:sids,
						ServiceDels:ServiceDels
					},
					success:function(res){
						switch(res){
							case "ok":
								alert('删除成功！');
								location.reload(true);
							break;
							case "e1":
								alert('非法访问！');
							break;
							case "":
								alert('删除失败！');
							break;
						}
					}
				});
			}
		});
	});


	//服务的删除
	$('.ServiceDel').click(function(){
		if(!confirm('确认删除？')){
			exit;
		}
		var sid = $(this).attr('data').trim();
		$.ajax({
			url:'http://www.service.top/index.php/Admin/Index/set_tokens',
			type:'post',
			data:{
				TokenName:'ServiceDel'
			},
			success:function(ServiceDel){
				$.ajax({
					url:'http://www.service.top/index.php/Model/ListService/del',
					type:'post',
					data:{
						sid:sid,
						ServiceDel:ServiceDel
					},
					success:function(res){
						//alert(res);
						switch(res){
							case 'ok':
								alert('删除成功！');
								location.reload(true);
							braek;
							case 'e1':
							case 'e3':
								alert('删除失败！');
							break;
							case 'e2':
								alert('非法访问！');
							break;
						}
					}
				});
			}
		});

	});


	//添加新服务按钮
	$('.ServiceaddBut').click(function(){
		$('.ServiceCon').removeClass('hidden');
	});

	//添加服务
	$('.Serviceadd').click(function(){
		var name = $('input[name=name]').val().trim();
		var tablename = $('input[name=tablename]').val().trim();
		$.ajax({
		//	url:'./index.php/Admin/Index/set_tokens',
			url:'http://www.service.top/index.php/Admin/Index/set_tokens',
			type:'post',
			data:{
				TokenName:'Serviceadd'
			},
			success:function(Serviceadd){
				$.ajax({
					url:'http://www.service.top/index.php/Model/ListService/add',
					type:'post',
					data:{
						name:name,
						tablename:tablename,
						Serviceadd:Serviceadd
					},
					success:function(res){
						switch(res){
							case 'e1':
								alert('数据不得为空');
							break;
							case 'e2':
								alert('表以存在');
							break;
							case 'e3':
								alert('非法访问！');
							break;
							case 'ok':
								alert('添加成功！');
								$('input[name=name]').val('');
								$('input[name=tablename]').val('');
								location.reload();
							break;
						}
					}
				});
			}
		});

	})



});